package com.example.notification;

import com.example.client.NotificationRequest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import java.time.LocalDateTime;

@Slf4j
@Service
public record NotificationService(NotificationRepository notificationRepository) {

    public void notifyCustomer(NotificationRequest request) {
        log.info("准备发送通知给客户: {}", request.toCustomerEmail());

        Notification notification = Notification.builder()
                .message(request.message())
                .sentAt(LocalDateTime.now())
                .toCustomerEmail(request.toCustomerEmail())
                .toCustomerId(request.toCustomerId())
                .build();

        Notification savedNotification = notificationRepository.save(notification);
        log.info("通知已保存到数据库: {}", savedNotification);
    }
}